﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using FBWMS.Properties;

namespace FBWMS
{
    public partial class F_COM_MsgBox : Form
    {
        public F_COM_MsgBox()
        {
            InitializeComponent();
        }

        private void F_COM_MsgBox_Load(object sender, EventArgs e)
        {        
            _msg = this;
        }

        public static F_COM_MsgBox _Msg
        {
            get
            {
                return _msg;
            }
            set
            {
                _msg = value;
            }
        }

        #region 警告画像ファイルパス*******************************************************

        public string sKeikokuRed = Application.StartupPath + "\\Img\\KEIKOKU_Red.jpg";          //エラー表示用画像
        public string sKeikokuYellow = Application.StartupPath + "\\Img\\KEIKOKU_Yellow.jpg";    //警告表示用ラベル

        #endregion ************************************************************************

        #region パス文字列*****************************************************************
                
        private static F_COM_MsgBox _msg;//　　//msgフィールド　　　

        #endregion ************************************************************************

        #region P_Msg_Show(メッセージ単数)*************************************************

        ////////////////////////////////////////////////////////////////////////////
        // OutLine   : P_Msg_Show
        // Parameter : iMtnMode     :   int     :   アイコンモード : 0,1,2
        //           : iBtnMode     :   int     :   釦モード
        //           : sMessage     :   string  :   表示文字列
        // Return    : なし
        // Contents  : メッセージの状態、ボタン、ラベルの種別を判定し画面に表示する
        // Makes     : 渡辺
        // History   : 2007/06/14       : 初版
        //           :
        ////////////////////////////////////////////////////////////////////////////
        public void P_Msg_Show(int iMtnMode, int iBtnMode, string sMessage)
        {
            try
            {
                //------------------------------------------------------
                //アイコン設定
                //------------------------------------------------------
                switch (iMtnMode)
                {
                    //標準表示
                    case G_CommonDefine.G_MsgBox_IconNormal:
                        this.BackColor = SystemColors.Control;
                        this.pic_Warning.Image = null;
                        break;
                    //警告表示
                    case G_CommonDefine.G_MsgBox_IconCaution:
                        this.BackColor = Color.Yellow;
                        this.pic_Warning.Image = new Bitmap(sKeikokuYellow);
                        break;
                    //エラー表示
                    case G_CommonDefine.G_MsgBox_IconERR:
                        this.BackColor = Color.Red;
                        this.pic_Warning.Image = new Bitmap(sKeikokuRed);
                        break;
                    default:
                        break;
                }

                //------------------------------------------------------
                //ボタン指定
                //------------------------------------------------------
                switch (iBtnMode)
                {
                    //OK-ONLY
                    case G_CommonDefine.G_MsgBox_OKOnly:
                        this.btn_Left.Visible = false;
                        this.btn_Right.Visible = false;
                        this.btn_Yes.Visible = false;
                        this.btn_No.Visible = false;
                        this.btn_OK.Visible = true;
                        this.lbl_Slash.Visible = false;
                        this.lbl_Record_Now.Visible = false;
                        this.lbl_Record_Total.Visible = false;
                        G_CommonDefine.G_MsgBox_btnMode = G_CommonDefine.G_MsgBox_OKOnly;
                        break;
                    //YES-NO
                    case G_CommonDefine.G_MsgBox_YesNo:
                        this.btn_Left.Visible = false;
                        this.btn_Right.Visible = false;
                        this.btn_Yes.Visible = true;
                        this.btn_No.Visible = true;
                        this.btn_OK.Visible = false;
                        this.lbl_Slash.Visible = false;
                        this.lbl_Record_Now.Visible = false;
                        this.lbl_Record_Total.Visible = false;
                        G_CommonDefine.G_MsgBox_btnMode = G_CommonDefine.G_MsgBox_YesNo;
                        break;
                    //Left-Right
                    case G_CommonDefine.G_MsgBox_LeftRight:
                        this.btn_Left.Visible = true;
                        this.btn_Right.Visible = true;
                        this.btn_Yes.Visible = false;
                        this.btn_No.Visible = false;
                        this.btn_OK.Visible = true;
                        this.lbl_Slash.Visible = true;
                        this.lbl_Record_Now.Visible = true;
                        this.lbl_Record_Total.Visible = true;
                        G_CommonDefine.G_MsgBox_btnMode = G_CommonDefine.G_MsgBox_LeftRight;
                        break;
                    default:
                        break;
                }

                //------------------------------------------------------
                //メッセージ指定
                //------------------------------------------------------                
                lbl_Message.Text = sMessage;
            }
            catch
            {
                Debug.WriteLine(Resources.失敗);
            }
        }

        #endregion ************************************************************************

        #region P_Msg_Show(メッセージ複数)*************************************************

        //現在のレコード
        private int int_Record_Now = 1;

        //総レコード数
        private int int_Record_Total = 0;

        //メッセージリスト
        private List<string> lst_errorMsg = new List<string>();

        ////////////////////////////////////////////////////////////////////////////
        // OutLine   : P_Msg_Show
        // Parameter : iMtnMode     :   int     :   アイコンモード : 0,1,2
        //           : iBtnMode     :   int     :   釦モード
        //           : lst_sMessage :   List    :   表示文字リスト
        // Return    : なし
        // Contents  : メッセージの状態、ラベルの種別を判定し画面に表示する
        // Makes     : 渡辺
        // History   : 2007/06/14       : 初版
        //           :
        ////////////////////////////////////////////////////////////////////////////
        public void P_Msg_Show(int iMtnMode, int iBtnMode, List<string> lst_sMessage)
        {
            try
            {
                //------------------------------------------------------
                //アイコン設定
                //------------------------------------------------------
                switch (iMtnMode)
                {
                    //標準表示
                    case G_CommonDefine.G_MsgBox_IconNormal:
                        this.BackColor = SystemColors.Control;
                        this.pic_Warning.Image = null;
                        break;
                    //警告表示
                    case G_CommonDefine.G_MsgBox_IconCaution:
                        this.BackColor = Color.Yellow;
                        this.pic_Warning.Image = new Bitmap(sKeikokuYellow);
                        break;
                    //エラー表示
                    case G_CommonDefine.G_MsgBox_IconERR:
                        this.BackColor = Color.Red;
                        this.pic_Warning.Image = new Bitmap(sKeikokuRed);
                        break;
                    default:
                        break;
                }

                //------------------------------------------------------
                //ボタン指定(Left-Rightのみ)
                //------------------------------------------------------                
                this.btn_Left.Visible = true;
                this.btn_Right.Visible = true;
                this.btn_Yes.Visible = false;
                this.btn_No.Visible = false;
                this.btn_OK.Visible = true;
                this.lbl_Slash.Visible = true;
                this.lbl_Record_Now.Visible = true;
                this.lbl_Record_Total.Visible = true;
                G_CommonDefine.G_MsgBox_btnMode = G_CommonDefine.G_MsgBox_LeftRight;

                //------------------------------------------------------
                //メッセージ指定
                //------------------------------------------------------

                this.lst_errorMsg = lst_sMessage;

                this.int_Record_Total = lst_errorMsg.Count;

                this.int_Record_Now = 1;

                this.lbl_Record_Total.Text = this.int_Record_Total.ToString();

                this.lbl_Record_Now.Text = this.int_Record_Now.ToString();

                this.btn_Left.Enabled = false;

                if (1 < int_Record_Total)
                {
                    this.btn_Right.Enabled = true;
                }
                else
                {
                    this.btn_Right.Enabled = false;
                }

                lbl_Message.Text = (string)this.lst_errorMsg[this.int_Record_Now - 1];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        #endregion ************************************************************************

        #region ボタン押下処理*************************************************************

        //OKボタン押下
        private void btn_OK_Click(object sender, EventArgs e)
        {
            this.Close();
        }        

        //Yesボタン押下
        private void btn_Yes_Click(object sender, EventArgs e)
        {
            G_CommonDefine.G_MsgBox_YesNoRetern = true;
            this.Close();
        }

        //NOボタン押下
        private void btn_No_Click(object sender, EventArgs e)
        {
            G_CommonDefine.G_MsgBox_YesNoRetern = false;
            this.Close();
        }

        //←ボタン押下
        private void btn_Left_Click(object sender, EventArgs e)
        {
            this.int_Record_Now--;

            this.lbl_Record_Now.Text = this.int_Record_Now.ToString();

            this.lbl_Message.Text = (string)this.lst_errorMsg[this.int_Record_Now - 1];

            if (this.int_Record_Now < this.int_Record_Total)
            {
                this.btn_Right.Enabled = true;
            }

            if (this.int_Record_Now.Equals(1))
            {
                this.btn_Left.Enabled = false;
            }
        }

        //→ボタン押下
        private void btn_Right_Click(object sender, EventArgs e)
        {
            this.int_Record_Now++;

            this.lbl_Record_Now.Text = this.int_Record_Now.ToString();

            this.lbl_Message.Text = (string)this.lst_errorMsg[this.int_Record_Now - 1];

            if (1 < this.int_Record_Now)
            {
                this.btn_Left.Enabled = true;
            }

            if (this.int_Record_Now.Equals(this.int_Record_Total))
            {
                this.btn_Right.Enabled = false;
            }
        }

        #endregion ************************************************************************       

        private void F_COM_MsgBox_Activated(object sender, EventArgs e)
        {
            switch (G_CommonDefine.G_MsgBox_btnMode)
            {
                //OK-ONLY
                case G_CommonDefine.G_MsgBox_OKOnly:
                    G_CommonDefine.F_COM_MsgBox.Controls["btn_OK"].Focus();
                    break;
                //YES-NO
                case G_CommonDefine.G_MsgBox_YesNo:
                    G_CommonDefine.F_COM_MsgBox.Controls["btn_NO"].Focus();
                    break;
                //Left-Right
                case G_CommonDefine.G_MsgBox_LeftRight:
                    G_CommonDefine.F_COM_MsgBox.Controls["btn_Right"].Focus();
                    break;
                default:
                    break;
            }
        }
    }
}